﻿
@{
    Layout = null;
}
@model List<shipping_address_dto>
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">

<head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <title>地址管理</title>
    <meta name="viewport" content="width=device-width,initial-scale=1.0, minimum-scale=1.0,maximum-scale=1.0, user-scalable=no" />
    <link href="~/Content/css/base.css" rel="stylesheet" />
    <link rel="stylesheet" href="~/Content/css/tuoken.css" />
    <script type="text/javascript" src="http://apps.bdimg.com/libs/jquery/2.1.4/jquery.min.js"></script>
    <script type="text/javascript" src="~/Content/js/base.js"></script>
    <script src="~/Content/js/layer/1.9.3/layer.js"></script>
    <link href="~/Content/js/layer/1.9.3/layui.css" rel="stylesheet" />
</head>

<body>
    @*<div class="header fn-shadow">
            <a href="javascript:history.go(-1);">
                <span class="back"></span>
            </a>
            <div class="hdtitle">
                地址管理
            </div>
        </div>*@

    <div class="property">
        <div class="choseAddress addressAdmin">
            @{ var returnUrl = Request.QueryString["returnUrl"]; }
            @if (Model.Count > 0) {
                int i = 0;


                foreach (var item in Model) {
                    i++;
                    <div class="item">
                        <div class="top clear" onclick="@(!string.IsNullOrEmpty(returnUrl)?"location.href='"+returnUrl+"&addressId=" + item.id+"'":"javascript:void(0)")">
                            <span class="fn-right">@item.phone</span>
                            <span>收货人：@item.ship_to</span>
                        </div>
                        <p class="col-gray1" onclick="@(!string.IsNullOrEmpty(returnUrl)?"location.href='"+returnUrl+"&addressId=" + item.id+"'":"javascript:void(0)")">收货地址：@(item.region_name + item.address)</p>
                        <div class="bottom clear">
                            <a class="fn-right j-delect col-gray1" href="javascript:;" data-id="@item.id">删除</a>
                            <a class="fn-right j-edit col-gray1" href="/user/adress?id=@item.id@(!string.IsNullOrEmpty(returnUrl) ? "&returnUrl=" + returnUrl+"&addressId=" + item.id :"")">编辑</a>
                            <input id="radio@(i)" type="radio" name="address" @(item.is_default ? "checked" : "") class="defalut" data-id="@item.id">
                            <label class="j-chose" for="radio@(i)">
                                <i></i>默认地址
                            </label>
                        </div>
                    </div>
                }

            }


            <a href="/user/adress?id=0&returnUrl=@returnUrl" class="settingbtn">新增地址</a>
        </div>
    </div>

    <script type="text/javascript">
        $(function () {
            $(".j-delect").click(function () {
                var id = $(this).attr("data-id");
                layer.confirm('您确定要删除么', {
                    btn: ['确定', '取消'] //按钮
                }, function () {
                    $.ajax({
                        type: "POST",//方法类型
                        dataType: "json",//预期服务器返回的数据类型
                        url: "/user/DelAdress",//url
                        data: { id: id },
                        success: function (result) {
                            if (result.result_code == 1000) {
                                layer.msg(result.result_msg);
                                window.location.reload();
                            } else {
                                layer.msg(result.result_msg);
                                setTimeout(function () { window.location.reload(); }, 1000);
                            }
                        }
                    });
                }, function () {

                });
            })
            $('.defalut').click(function () {
                var that = $(this);
                if (that.attr('checked')) return;
                var data = { id: that.attr('data-id') }
                $.ajax({
                    //几个参数需要注意一下
                    type: "POST",//方法类型
                    dataType: "json",//预期服务器返回的数据类型
                    url: "/user/UpdateDefault",//url
                    data: data,
                    success: function (result) {
                        if (result.result_code == 1000) {

                        } else {
                            layer.msg(result.result_msg);
                        }
                    },
                    error: function () {
                        layer.msg("异常！");
                    }
                });
            })
        })
    </script>
</body>

</html>
